package org.com.blbl.SubPartitionCount;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.com.blbl.bean.SubPartitionBean;

import java.io.IOException;

public class SubPartitionCountMapper extends Mapper<LongWritable, Text, SubPartitionBean, LongWritable> {
    SubPartitionBean keyOut = new SubPartitionBean();
    LongWritable valueOut = new LongWritable(1);
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, SubPartitionBean, LongWritable>.Context context) throws IOException, InterruptedException {


        //将读取的一行内容根据分隔符进行拆分
        String[] files = value.toString().split(",");
        String partition = files[files.length - 7];
        String subPartition = files[files.length - 6];
        keyOut.set(partition, subPartition); // 设置输出键
        context.write(keyOut, valueOut); // 输出键值对

    }
}
